<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../templates/applicationTemplate.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:a4j="http://richfaces.org/a4j" >

    <ui:define name="title">
        SGA - #{bundle.teamViewTitle}
    </ui:define>

    <ui:define name="content">

        <h:form>

            <rich:panel>
                <f:facet name="header">
                    <h:outputText styleClass="mainPanel" value="#{bundle.teamViewTitle}" />
                </f:facet>

                <h:panelGrid columns="2" >

                    <rich:dataTable keepSaved="true" id="teamsTable"
                                    var="record" rowKeyVar="rowKey" 
                                    rowClasses="odd-row, even-row" rows="20"
                                    value="#{teamManagedBean.tableHandler.dataModel}" 
                                    onrowclick="processRowClick(#{rowKey});" 
                                    onrowmouseover="jQuery(this).addClass('active-row');"
                                    onrowmouseout="jQuery(this).removeClass('active-row');" >

                        <ui:include src="./../templates/arrangeableColumnTemplate.xhtml" >
                            <ui:param name="property" value="name" />
                            <ui:param name="columnTitleKey" value="teamName" />
                            <ui:param name="bean" value="#{teamManagedBean.tableHandler}" />
                            <ui:param name="sortingEnabled" value="true"/>
                            <ui:param name="filteringEnabled" value="true"/>
                            <ui:param name="tableID" value="teamsTable" />
                            <ui:param name="scrollerID" value="scroller" />
                            <ui:param name="tooltipText" value="#{bundle.columnTooltipText}" />
                            <ui:param name="columnValue" value="#{record['name']}" />
                        </ui:include>

                        <ui:include src="./../templates/arrangeableColumnTemplate.xhtml" >
                            <ui:param name="property" value="managerName" />
                            <ui:param name="bean" value="#{teamManagedBean.tableHandler}" />
                            <ui:param name="sortingEnabled" value="true"/>
                            <ui:param name="filteringEnabled" value="true"/>
                            <ui:param name="tableID" value="teamsTable" />
                            <ui:param name="scrollerID" value="scroller" />
                            <ui:param name="tooltipText" value="#{bundle.columnTooltipText}" />
                            <ui:param name="columnValue" value="#{record['managerName']}" />
                        </ui:include>

                        <rich:column style="text-align: center;" rendered="#{request.isUserInRole('Archiver')}">

                            <f:facet name="header" >
                                <h:outputText styleClass="arrangeableHeader" 
                                              value="#{bundle.arrangeableTableActionsColumn}" />
                            </f:facet>

                            <a4j:commandButton image="/resources/icons/Button-Remove-icon.png"
                                               execute="@this" render="@none" 
                                               onclick="event.stopPropagation();"
                                               oncomplete="#{rich:component('deleteConfirmWindow')}.show();" 
                                               value="" styleClass="iconizedButton" >
                                <f:setPropertyActionListener target="#{teamManagedBean.currentState}" value="DELETE" />
                                <f:setPropertyActionListener target="#{teamManagedBean.currentlyManagedTeam}" value="#{record}" />
                            </a4j:commandButton> 
                            <a4j:commandButton image="/resources/icons/Change-pencil-icon.png" 
                                               value="" styleClass="iconizedButton"
                                               action="#{teamManagedBean.processActionAndRedirect('EDIT')}" >
                                <f:setPropertyActionListener target="#{teamManagedBean.currentlyManagedTeam}" value="#{record}" />
                            </a4j:commandButton>
                        </rich:column>

                        <f:facet name="footer" >
                            <rich:dataScroller id="scroller" />
                        </f:facet>
                    </rich:dataTable>

                    <ui:include src="./teamDetail.xhtml" >
                        <ui:param name="teamDetailPanelID" value="teamDetailPanel" />
                        <ui:param name="team" value="#{teamManagedBean.currentlyDetailedTeam}" />
                    </ui:include>

                </h:panelGrid>

            </rich:panel>

            <a4j:jsFunction name="processRowClick" execute="@this" 
                            action="#{teamManagedBean.processClickEvent(rowKey)}"
                            render="teamDetailPanel" >
                <a4j:param name="rowKey" assignTo="#{rowKey}" />
            </a4j:jsFunction>


            <a4j:jsFunction name="remove" execute="@this" render="teamsTable teamDetailPanel"
                            action="#{teamManagedBean.handleAction}" 
                            oncomplete="#{rich:component('deleteConfirmWindow')}.hide();" />

            <ui:include src="./../dialogs/confirmationDialogWindow.xhtml" >
                <ui:param name="confirmDialogWindowID" value="deleteConfirmWindow" />
                <ui:param name="confirmationText" value="#{bundle.deleteModalForm}" />
                <ui:param name="acceptButtonText" value="#{bundle.deleteButton}" />
                <ui:param name="acceptEventFunction" value="remove()" />
            </ui:include>

        </h:form>

    </ui:define>


</ui:composition>
